using System;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;

namespace OpenComposite.Mapper
{
	#region Internal Class: MapperSettings
	[Serializable]
	[XmlType(Namespace = "http://www.theopencomposite.com/internal/MapperSettings")]
	[XmlRoot(Namespace = "http://www.theopencomposite.com/internal/MapperSettings")]
	public class MapperSettings
	{
		#region Initialization
		public MapperSettings()
		{
			_mappingItems = new List<MappingItem>();
		}
		#endregion

		#region MappingItems
		private List<MappingItem> _mappingItems;
		[XmlIgnore]
		public List<MappingItem> MappingItems
		{
			get { return _mappingItems; }
		}
		public MappingItem[] MappingItemArray
		{
			get { return _mappingItems.ToArray(); }
			set
			{
				if ( _mappingItems == null ) {
					_mappingItems = new List<MappingItem>();
				} else {
					_mappingItems.Clear();
				}
				_mappingItems.AddRange(value);
			}
		}
		#endregion

		#region IsCustomXSLT
		private bool _isCustomXSLT;
		public bool IsCustomXSLT
		{
			get { return _isCustomXSLT; }
			set { _isCustomXSLT = value; }
		}
		#endregion

		#region ExportPath
		private string _exportPath;
		public string ExportPath
		{
			get { return _exportPath; }
			set { _exportPath = value; }
		}
		#endregion
	}
	#endregion

	#region Class: MappingItem
	[Serializable]
	public class MappingItem
	{
		public MappingItem()
		{
			ConnectionPath = new GraphicsPath();
		}
		public MappingItem(TreeNode source, TreeNode target)
		{
			SourceNode = source;
			TargetNode = target;
			ConnectionPath = new GraphicsPath();
		}

		[NonSerialized, XmlIgnore]
		public TreeNode SourceNode = null;
		[NonSerialized, XmlIgnore]
		public TreeNode TargetNode = null;
		[NonSerialized, XmlIgnore]
		public GraphicsPath ConnectionPath = null;

		public string SourcePath
		{
			get
			{
				if ( SourceNode != null )
					return SourceNode.FullPath;
				else
					return _sourcePath;
			}
			set { _sourcePath = value; }
		}
		public string TargetPath
		{
			get
			{
				if ( TargetNode != null )
					return TargetNode.FullPath;
				else
					return _targetPath;
			}
			set { _targetPath = value; }
		}

		private string _sourcePath = "";
		private string _targetPath = "";

	}
	#endregion

	#region Class: TreeNodeInfos
	public class TreeNodeInfos
	{
		public TreeNodeInfos()
		{
			DataType = string.Empty;
			Mappings = new List<MappingItem>();
			XsltNodes = new Dictionary<TreeNode, XsltNodeDetails>();
		}
		public TreeNodeInfos(XmlSchemaObject schemaobj)
			: this()
		{
			SchemaObject = schemaobj;
		}
		public TreeNodeInfos(string datatype, MappingItem mapping)
			: this()
		{
			DataType = datatype;
			if ( mapping != null )
				Mappings.Add(mapping);
		}

		public string DataType;
		public List<MappingItem> Mappings;
		public XmlSchemaObject SchemaObject;
		public XmlNode XsltNode = null;
		public XmlNode XsltNode2 = null;
		public Dictionary<TreeNode, XsltNodeDetails> XsltNodes = null;
		public string VariableName = null;
		public string Namespace = null;
		public string Prefix = null;

		public override string ToString()
		{
			string str = string.Empty;
			if ( !string.IsNullOrEmpty(this.DataType) ) {
				str = string.Format("{{{0}}}", this.DataType);
			}
			if ( !string.IsNullOrEmpty(this.Namespace) ) {
				if ( str != string.Empty ) str += " ";
				str += this.Namespace;
			}
			return str;
		}
	}
	public class XsltNodeDetails
	{
		public XsltNodeDetails()
		{
			treenode = null;
			rootxmlnode = null;
			targetxmlnode = null;
		}
		public XsltNodeDetails(TreeNode tn, XmlNode xnroot, XmlNode xntarget)
		{
			treenode = tn;
			rootxmlnode = xnroot;
			targetxmlnode = xntarget;
		}
		public TreeNode treenode;
		public XmlNode rootxmlnode;
		public XmlNode targetxmlnode;
	}
	#endregion

	#region Class: GlobalElementType
	public class GlobalElementType
	{
		public GlobalElementType(string name, XmlSchemaObject type)
		{
			this.name = name;
			this.type = type;
		}

		public override string ToString()
		{
			return name;
		}

		public string Get()
		{
			return name;
		}

		public void Set(string name)
		{
			this.name = name;
		}

		public string name;
		public XmlSchemaObject type;
	}
	#endregion

}
